/**
 * @file       Rect_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "Rect.h"
#include "gtest/gtest.h"
#include "Point.h"
namespace NS_LCD_AFW
{

class CRect_test: public ::testing::Test
{
public:
	virtual ~CRect_test()
	{
	}
public:
	virtual void SetUp()
	{
	}
	virtual void TearDown()
	{
	}
};
TEST_F(CRect_test,test_defaultConstruction)
{
	CRect rect;
	EXPECT_EQ(-1, rect.getLeft());
	EXPECT_EQ(-1, rect.getTop());
	EXPECT_EQ(-1, rect.getWidth());
	EXPECT_EQ(-1, rect.getHight());
	EXPECT_EQ(CPoint(-1,-1), rect.getLeftTop());
	EXPECT_EQ(CPoint(-3,-3), rect.getRightBottom());
	EXPECT_FALSE(rect.isValidRect());
	EXPECT_TRUE(rect.isRectEmpty());
	EXPECT_TRUE(rect.isRectNull());
}
TEST_F(CRect_test,test_Construction_2)
{
	CRect rect(0,1,2,99);
	EXPECT_EQ(0, rect.getLeft());
	EXPECT_EQ(1, rect.getTop());
	EXPECT_EQ(2, rect.getWidth());
	EXPECT_EQ(99, rect.getHight());
	EXPECT_EQ(CPoint(0,1), rect.getLeftTop());
	EXPECT_EQ(CPoint(1,99), rect.getRightBottom());
	EXPECT_TRUE(rect.isValidRect());
	EXPECT_FALSE(rect.isRectEmpty());
	EXPECT_FALSE(rect.isRectNull());
}
TEST_F(CRect_test,test_Construction_3)
{
	CPoint pt1(0,1);
	CPoint pt2(2,99);
	CRect rect(pt1,pt2);
	EXPECT_EQ(0, rect.getLeft());
	EXPECT_EQ(1, rect.getTop());
	EXPECT_EQ(3, rect.getWidth());
	EXPECT_EQ(99, rect.getHight());
	EXPECT_EQ(pt1, rect.getLeftTop());
	EXPECT_EQ(pt2, rect.getRightBottom());
	EXPECT_TRUE(rect.isValidRect());
	EXPECT_FALSE(rect.isRectEmpty());
	EXPECT_FALSE(rect.isRectNull());
}
TEST_F(CRect_test,test_getCenterPoint)
{
	CRect rect(0,1,2,10);
	EXPECT_EQ(CPoint(1,6),rect.getCenterPoint());
}
TEST_F(CRect_test,test_isRectEmpty)
{
	CRect rect(0,1,2,10);
	EXPECT_FALSE(rect.isRectEmpty());
	rect.setHight(0);
	EXPECT_TRUE(rect.isRectEmpty());
	rect.setHight(-1);
	EXPECT_TRUE(rect.isRectEmpty());
	rect.setHight(1);
	EXPECT_FALSE(rect.isRectEmpty());

	rect.setWidth(0);
	EXPECT_TRUE(rect.isRectEmpty());
	rect.setWidth(-1);
	EXPECT_TRUE(rect.isRectEmpty());
	rect.setWidth(1);
	EXPECT_FALSE(rect.isRectEmpty());

	rect.setTop(0);
	rect.setLeft(0);
	EXPECT_FALSE(rect.isRectEmpty());
	rect.setTop(-1);
	rect.setLeft(-1);
	EXPECT_FALSE(rect.isRectEmpty());

	rect.setTop(1);
	rect.setLeft(1);
	EXPECT_FALSE(rect.isRectEmpty());
}
TEST_F(CRect_test,test_isRectNull)
{
	CRect rect(0,1,2,10);
	EXPECT_FALSE(rect.isRectNull());
	rect.setHight(0);
	EXPECT_TRUE(rect.isRectNull());
	rect.setHight(-1);
	EXPECT_TRUE(rect.isRectNull());
	rect.setHight(1);
	EXPECT_FALSE(rect.isRectNull());

	rect.setWidth(0);
	EXPECT_TRUE(rect.isRectNull());
	rect.setWidth(-1);
	EXPECT_TRUE(rect.isRectNull());
	rect.setWidth(1);
	EXPECT_FALSE(rect.isRectNull());

	rect.setTop(0);
	EXPECT_FALSE(rect.isRectNull());
	rect.setTop(-1);
	EXPECT_TRUE(rect.isRectNull());
	rect.setTop(1);
	EXPECT_FALSE(rect.isRectNull());


	rect.setLeft(0);
	EXPECT_FALSE(rect.isRectNull());
	rect.setLeft(-1);
	EXPECT_TRUE(rect.isRectNull());
	rect.setLeft(1);
	EXPECT_FALSE(rect.isRectNull());

}
TEST_F(CRect_test,test_isEqualWith)
{
	CRect rect1(0,1,2,10);
	CRect rect2(0,1,2,10);
	EXPECT_EQ(rect1,rect2);
	EXPECT_TRUE(rect1.isEqualWith(rect2));

}
TEST_F(CRect_test,test_isPointInRect)
{
	CRect rect1(0,0,2,2);
	CPoint pt(0,0);
	EXPECT_TRUE(rect1.isPointInRect(pt));
	pt.setX(-1);
	EXPECT_FALSE(rect1.isPointInRect(pt));
	pt.setX(2);
	EXPECT_FALSE(rect1.isPointInRect(pt));
	pt.setX(1);
	EXPECT_TRUE(rect1.isPointInRect(pt));

	pt.setY(-1);
	EXPECT_FALSE(rect1.isPointInRect(pt));
	pt.setY(2);
	EXPECT_FALSE(rect1.isPointInRect(pt));
	pt.setY(1);
	EXPECT_TRUE(rect1.isPointInRect(pt));
}
TEST_F(CRect_test,test_offsetRect)
{

	CRect rect1(0,0,1,1);
	rect1.offsetRect(1,2);
	EXPECT_EQ(CRect(1,2,1,1),rect1);
}
TEST_F(CRect_test,test_operator_eq)
{

	CRect rect1(0,0,1,1);
	CRect rect2(0,0,1,1);
	bool b = (rect1 == rect2);
	EXPECT_TRUE(b);
}
TEST_F(CRect_test,test_operator_ne)
{
	CRect rect1(0,0,1,1);
	CRect rect2(0,0,1,2);
	bool b = (rect1 != rect2);
	EXPECT_TRUE(b);
}
} /* namespace NS_LCD_AFW */
